package com.packer.ext.base;

import android.support.annotation.DrawableRes;
import android.widget.ImageView;

import com.lasingwu.baselibrary.ImageLoaderManager;
import com.lasingwu.baselibrary.ImageLoaderOptions;
import com.lasingwu.baselibrary.LoaderResultCallBack;
import com.packer.ext.util.Utils;

/**
 * ${DESC}
 *
 * @author pengbinghan
 *         created at 2018/4/18
 */
public class ImageLoader {
    private static int holderDrawbale;
    private static int errorDrawbale;

    public static void setDefaultPlaceHolder( @DrawableRes int holder, @DrawableRes int errHolder) {
        holderDrawbale = holder;
        errorDrawbale = errHolder;
    }


    public static void showImage(ImageView view, String url) {
        showImage(view, url, holderDrawbale, errorDrawbale, null, false);
    }

    public static void showCircleImage(ImageView view, String url) {
        showImage(view, url, holderDrawbale, errorDrawbale, null, true);
    }

    public static void showImage(ImageView view, String url, LoaderResultCallBack callBack) {
        showImage(view, url, holderDrawbale, errorDrawbale, callBack, false);
    }

    public static void showCircleImage(ImageView view, String url, LoaderResultCallBack callBack) {
        showImage(view, url, holderDrawbale, errorDrawbale, callBack, true);
    }

    public static void showImage(ImageView view, String url, @DrawableRes int holder, @DrawableRes int errHolder, LoaderResultCallBack callBack) {
        showImage(view, url, holder, errHolder, callBack,false);
    }
    public static void showCircleImage(ImageView view, String url, @DrawableRes int holder, @DrawableRes int errHolder, LoaderResultCallBack callBack) {
        showImage(view, url, holder, errHolder, callBack,true);
    }

    private static void showImage(ImageView view, String url, @DrawableRes int holder, @DrawableRes int errHolder
            , LoaderResultCallBack callBack, boolean isCircle) {
        ImageLoaderOptions.Builder builder = new ImageLoaderOptions.Builder(view, url);
        builder.placeholder(holder)
                .error(errHolder);
        if (callBack != null) {
            builder.error(callBack);
        }
        if (isCircle) {
            builder.isCircle();
        }
        ImageLoaderManager.getInstance().showImage(builder.build());
    }

    public static void resume() {
        ImageLoaderManager.getInstance().resume(Utils.getApp());
    }

    public static void pause() {
        ImageLoaderManager.getInstance().pause(Utils.getApp());
    }

}
